#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char code
s8[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};
sbit K1=P3^2;
sbit K2=P3^3;
sbit K3=P3^4;
sbit K4=P3^5;
sbit fmq=P3^6;
unsigned char x=0,m=0,shi,ge;
void delay1ms(uint i)
{
	uchar j;
	while(i--)
		for(j=0;j<115;j++);
}

void int1(void) interrupt 2
{
	EX1=0;
	if(K2==0)
	{
		delay1ms(15);
		if(K2==0)
		{
			P2=0xc0;
			P0=0xc0;
		}
	}
	EX1=1;
}

void beep()
{
	fmq=0;
	delay1ms(2);
	fmq=1;
	delay1ms(2);
}

void Display(unsigned char y)
{
	shi=y/10;
	ge=y%10;
	P0=s8[shi];
	P2=s8[ge];
}

void k3(void)
{
	uchar t;
	Display(11);
	for(t=0;t<250;t++)
	beep();
	fmq=1;
	delay1ms(1000);
}

void k4()
{
	ET1=1;
	TMOD=0x10;
	TH1=(65536-50000)/256;
	TL1=(65536-50000)%256;
	TR1=1;
	while(1)
	{
		Display(x);
	}
}
	
void Time1(void) interrupt 3
{
	unsigned char n;
	n=n+1;
	if(n==20)
	{
		x++;
		n=0;
	}
	TH1=(65536-50000)/256;
	TL1=(65536-50000)%256;
	if(x==60)
		TR1=0;
}

void main()
{
	EA=1;
	EX1=1;
	IT1=1;
	while(1)
	{
		if(K3==0)
		{
			delay1ms(15);
			if(K3==0)
			{
				k3();
			}
			while(!K3);
		}
		if(K4==0)
		{
			delay1ms(15);
			if(K4==0)
			{
				k4();
			}
			while(!K4);
		}
	}
}
